(*****************************************************************************
 * Delphi Plug-in Framework (DPF)
 * Copyright (C) 2006-2007 Tao Yuan
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the
 * License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.                                                               }
 *
 * The Initial Developer of the Original Code is Tao Yuan. Portions created by
 * Tao Yuan are Copyright (C) Tao Yuan (taoy.cn att gmail dott com)
 * All rights reserved.
 *****************************************************************************)
unit RDExceptions;

interface

uses
  SysUtils;

type
  EPFException = class(Exception)
  private
    cause: Exception;
    data: string;
    messageKey: string;
    packageName: string;
  public
    constructor Create(aPackageName, aMessageKey, aData: string; e: Exception);
        overload;
    constructor Create(aPackageName, aMessageKey, aData: string); overload;
    constructor Create(aPackageName, aMessageKey: string); overload;
    constructor Create(aPackageName, aMessageKey: string; aData: array of string);
        overload;
    function getMessage: string; virtual;
  end;

  EIllegalArgument = class(EPFException);
  
  EPluginLifecycle = class(EPFException)
  public
  end;

  EClassNotFound = class(EPFException)
  end;

  EInvocationTarget = class(EPFException)
  end;

  EManifestProcessing = class(EPFException)
  end;

  EUnsupportedOperationException = class(Exception)
  end;

  EPluginLoader = class(EPFException)
  end;


implementation

constructor EPFException.Create(aPackageName, aMessageKey, aData: string; e:
    Exception);
begin
  packageName := aPackageName;
  messageKey := aMessageKey;
  data := aData;
  cause := E;
  inherited Create(getMessage);
end;

constructor EPFException.Create(aPackageName, aMessageKey, aData: string);
begin
  Self.Create(aPackageName, aMessageKey, aData, nil);
end;

constructor EPFException.Create(aPackageName, aMessageKey: string);
begin
  Self.Create(aPackageName, aMessageKey, '', nil);
end;

constructor EPFException.Create(aPackageName, aMessageKey: string; aData: array
    of string);
var
  s: string;
  I: Integer;
begin
  s := '';
  for I := 0 to High(aData) do
    if I < High(aData) then s := s + aData[I] + ','
    else s := s + aData[I];
  Self.Create(aPackageName, aMessageKey, s, nil);
end;

function EPFException.getMessage: string;
begin
  Result := Format('Package: %s; Message: %s; Data: %s',
    [packageName, messageKey, data]);
end;

end.
